import React,{Component} from "react"


export default class Login extends Component{
    constructor(props){
        super(props)
        this.state={
            username:"",
            password:""
        }
        this.change = this.change.bind(this)
    }
    change(e){
        this.setState({
            [e.target.id]:e.target.value
        })
    }
    login(){
        let {username,password} = this.state
        sessionStorage.setItem('user',JSON.stringify({"username":username,"password":password}))
        var path = sessionStorage.getItem('path')
        this.props.history.push(path)
        
    }
    render(){
        let {username,password} = this.state
        return <div>
            <input type="text" id="username" value={username} onChange={this.change}/>
            <input type="text" id="password" value={password} onChange={this.change}/>
            <button onClick={this.login.bind(this)}>登录</button>
        </div>
    }
}